module MainHandler (
        getCustomersAcid, 
        addNewHaircutAcid,
        getHaircutsAcid,
        addCustomerAcid,
        updateNameToCustomer,
        getCustomerByIdAcid,
        updatePerformedHaircutToCustomer
        
) where
import Customer
import Haircut
import PerformedHaircut
import Data.IORef
import WindowUtils
import Repositorium
import Data.Acid

{-
AUTOR:Gaston Charkiewicz
DESCRIPCION: base de datos del sistema. Atada con alambre, hasta que se haga una 
"pasada monadica".
OBSERVACIONES: utiliza una lista para almacenarlos.
-}


---------------------------------------------------------
---------------- FUNCIONES CON ACID ---------------------

addCustomerAcid state customer = do
    update state (AddNewCustomer customer)

getCustomersAcid state = do 
    customers <- query state GetAllCustomers
    return customers

--addNewHaircutAcid :: UpdateEvent event => AcidState (EventState event) -> Haircut -> IO (EventResult event)
addNewHaircutAcid state newHc = do
    update state (AddNewHaircut newHc)

getHaircutsAcid state = do
    haircuts <- query state GetAllHaircuts
    return haircuts

updateNameToCustomer customer newName state = do
    update state (UpdateCustomerName customer newName)

getCustomerByIdAcid int state = do
                index <- int
                customers <- getCustomersAcid state
                return (searchByIndex index customers)


updatePerformedHaircutToCustomer updatedCtm state = do
    update state (UpdateCustomer updatedCtm)

